package com.lhh.userservice.controller;

import com.lhh.springcommon.annotation.WebLog;
import com.lhh.springcommon.annotation.WithRequestId;
import com.lhh.springcommon.entity.Like;
import com.lhh.springcommon.utils.Response;
import com.lhh.userservice.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 点赞
 * @author 李厚航
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/like")
public class LikeController {


    private final UserLikeService userLikeService;


    @Autowired
    public LikeController(UserLikeService userLikeService) {
        this.userLikeService = userLikeService;
    }

    /**
     * 点赞或取消点赞
     * @param like
     * @return
     */
    @PostMapping("/addOrDeleteLike")
    @WithRequestId
    @WebLog
    public Response<Boolean> addOrDeleteLike(@RequestBody Like like){
        return Response.success(userLikeService.addOrDeleteLike(like));
    }

    /**
     * 查询是否点赞
     * @param vid
     * @return
     */
    @GetMapping("/isLike")
    @WithRequestId
    @WebLog
    public Response<Boolean> isLike(@RequestParam("uid") Integer uid,@RequestParam("vid") Integer vid){
        return Response.success(userLikeService.isLike(uid,vid));
    }

    /**
     * 获取视频点赞数
     * @param vid
     * @return
     */
    @GetMapping("/countVideoLike")
    @WithRequestId
    @WebLog
    public Response<Long> countVideoLike(@RequestParam("vid") Long vid){
        return Response.success(userLikeService.countLike(vid));
    }
}
